using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PTB2
{
    public partial class MainGui : Form
    {
    //*********************************** BEGIN * LE VINH PHUC * 0912343 ***************************//
        CPTB2 _cptb2 = new CPTB2();
        float n = 0.0f;
        
        public MainGui()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            lbketluan.Visible = false;
        }

        private void txta_TextChanged(object sender, EventArgs e)
        {
            if (float.TryParse(txta.Text, out n))
             {
                if ((_cptb2.HeSoA = float.Parse(txta.Text)) == 0)
                {
                    MessageBox.Show("He so a phai khac 0");
                }
                else
                    this.buttinhketqua.Enabled = true;
             }
             else MessageBox.Show("Phai la chu so");

        }

        private void txtb_TextChanged(object sender, EventArgs e)
        {
            if (float.TryParse(this.txtb.Text, out n))
            {
                _cptb2.HeSoB = float.Parse(txtb.Text);
            }
            else MessageBox.Show("Phai la chu so");
        }

        private void txtc_TextChanged(object sender, EventArgs e)
        {
            if (float.TryParse(this.txtc.Text, out n))
            {
                _cptb2.HeSoC = float.Parse(txtc.Text);
            }
            else MessageBox.Show("Phai la chu so");
        }

        private void buttinhketqua_Click(object sender, EventArgs e)
        {
            _cptb2.TinhDelta();
            if (_cptb2.Delta > 0)
            {
                _cptb2.Tinh2Nghiem();
                txtNghiem1.Text = _cptb2.Nghiem1.ToString();
                txtNghiem2.Text = _cptb2.Nghiem2.ToString();
            }

            if (_cptb2.Delta == 0)
            {
                _cptb2.Tinh1Nghiem();
                txtNghiem1.Text = _cptb2.Nghiem1.ToString();
                txtNghiem2.Text = _cptb2.Nghiem2.ToString();
            }

            if(_cptb2.Delta < 0)
            {
                lbketluan.Visible = true;
            }

        }
       
    }
    //*********************************** END * LE VINH PHUC * 0912343 ***************************//
}
